import {
	observer
} from 'mobx-react';
import {
	WeaFormItem,
} from 'ecCom';
import {
	WeaSwitch
} from 'comsMobx'

@observer
export default class NoLinkageForm extends React.Component {
	constructor(props) {
		super(props);
	}

	customRender = (c) => {
		const {
			form,
			isEdit,
			onFormChange,
			onBlur,
		} = this.props;

		return c.items.map((item, index) => {
			const {
				label,
				viewAttr,
				hasBorder,
				otherParams,
			} = item;

			const hasUnderline = () => {
				let b;
				if (viewAttr === 1) {
					if (hasBorder) {
						b = false;
					} else {
						if (otherParams) {
							if (otherParams.hasBorder) {
								b = false;
							} else {
								b = true;
							}
						} else {
							b = true;
						}
					}
				} else {
					b = false;
				}
				return b;
			}

			return (
				<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@80j1cj@${index}`}
			      label={label}
			      labelCol={{span:6}}
			      wrapperCol={{span:18}}
			      tipPosition={'bottom'}
			      error={form.getError(item)}
			      underline={hasUnderline()}
			      style={{padding:'4px 0'}}
	    		>
		    	  <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@qg0f90@${index}`} 
		    	  	fieldConfig={item} 
		    	  	form={form} 
		    	  	formParams={form.getFormParams()} 
		    	  	onChange={onFormChange} 
		    	  	onBlur={onBlur}/>
		    	</WeaFormItem>
			)
		});
	}

	render() {
		const {
			form,
		} = this.props;

		return (
			<div className='form'>
				{
					form.render({},{},true,this.customRender)
				}
			</div>
		);
	}
}